'''
Created on Feb 22, 2012

@author: daoxuandung
'''

"""
Provide URL routing for the whole website
"""

import webapp2
from google.appengine.ext import ndb
from webapp2_extras.routes import RedirectRoute

routes = [
          # Home page
          RedirectRoute('/home/', 
                      handler='web.home_page.EventHandler', 
                      name = 'home-page',
                      strict_slash=True),
          
          # Event page
          RedirectRoute('/event/', 
                      handler='web.event_page.EventHandler', 
                      name = 'event-page',
                      strict_slash=True),

          # Import contact
          RedirectRoute('/contact/google/', 
                      handler='web.import_contact.GoogleContactHandler', 
                      name = 'import-google-contact',
                      strict_slash=True),    
          
          # API
          # Feed
          RedirectRoute('/api/feed/create/', 
                      handler='api.feed.CreateHandler', 
                      name = 'feed-create',
                      strict_slash=True),
          RedirectRoute('/api/feed/read/', 
                      handler='api.feed.ReadHandler', 
                      name = 'feed-read',
                      strict_slash=True),
          RedirectRoute('/api/feed/update/', 
                      handler='api.feed.UpdateHandler', 
                      name = 'feed-update',
                      strict_slash=True),
          RedirectRoute('/api/feed/delete/', 
                      handler='api.feed.DeleteHandler', 
                      name = 'feed-delete',
                      strict_slash=True),    
                
          # Post
          RedirectRoute('/api/post/create/', 
                      handler='api.post.CreateHandler', 
                      name = 'post-create',
                      strict_slash=True),
          RedirectRoute('/api/post/read/', 
                      handler='api.post.ReadHandler', 
                      name = 'post-read',
                      strict_slash=True),
          RedirectRoute('/api/post/update/', 
                      handler='api.post.UpdateHandler', 
                      name = 'post-update',
                      strict_slash=True),
          RedirectRoute('/api/post/delete/', 
                      handler='api.post.DeleteHandler', 
                      name = 'post-delete',
                      strict_slash=True),

          # Comment
          RedirectRoute('/api/comment/create/', 
                      handler='api.comment.CreateHandler', 
                      name = 'comment-create',
                      strict_slash=True),
          RedirectRoute('/api/comment/read/', 
                      handler='api.comment.ReadHandler', 
                      name = 'comment-read',
                      strict_slash=True),
          RedirectRoute('/api/comment/update/', 
                      handler='api.comment.UpdateHandler', 
                      name = 'comment-update',
                      strict_slash=True),
          RedirectRoute('/api/comment/delete/', 
                      handler='api.comment.DeleteHandler', 
                      name = 'comment-delete',
                      strict_slash=True),
          RedirectRoute('/api/comment/post/<commentable_id:\d+>/', 
                      handler='api.comment.PostCommentsHandler', 
                      name = 'comment-post',
                      strict_slash=True),
          RedirectRoute('/api/comment/photo/<commentable_id:\d+>/', 
                      handler='api.comment.PhotoCommentsHandler', 
                      name = 'comment-photo',
                      strict_slash=True),

          # Invite
          RedirectRoute('/api/invite/create/', 
                      handler='api.invite.CreateHandler', 
                      name = 'invite-create',
                      strict_slash=True),
          RedirectRoute('/api/invite/read/', 
                      handler='api.invite.ReadHandler', 
                      name = 'invite-read',
                      strict_slash=True),
          RedirectRoute('/api/invite/update/', 
                      handler='api.invite.UpdateHandler', 
                      name = 'invite-update',
                      strict_slash=True),
          RedirectRoute('/api/invite/delete/', 
                      handler='api.invite.DeleteHandler', 
                      name = 'invite-delete',
                      strict_slash=True),

          # Message
          RedirectRoute('/api/message/create/', 
                      handler='api.message.CreateHandler', 
                      name = 'message-create',
                      strict_slash=True),
          RedirectRoute('/api/message/read/', 
                      handler='api.message.ReadHandler', 
                      name = 'message-read',
                      strict_slash=True),
          RedirectRoute('/api/message/update/', 
                      handler='api.message.UpdateHandler', 
                      name = 'message-update',
                      strict_slash=True),
          RedirectRoute('/api/message/delete/', 
                      handler='api.message.DeleteHandler', 
                      name = 'message-delete',
                      strict_slash=True),
          
           # Group
          RedirectRoute('/api/group/create/', 
                      handler='api.group.CreateHandler', 
                      name = 'group-create',
                      strict_slash=True),
          RedirectRoute('/api/group/read/', 
                      handler='api.group.ReadHandler', 
                      name = 'group-read',
                      strict_slash=True),
          RedirectRoute('/api/group/update/', 
                      handler='api.group.UpdateHandler', 
                      name = 'group-update',
                      strict_slash=True),
          RedirectRoute('/api/group/delete/', 
                      handler='api.group.DeleteHandler', 
                      name = 'group-delete',
                      strict_slash=True),         
          
          # Album
          RedirectRoute('/api/album/create/', 
                      handler='api.album.CreateHandler', 
                      name = 'album-create',
                      strict_slash=True),
          RedirectRoute('/api/album/read/', 
                      handler='api.album.ReadHandler', 
                      name = 'album-read',
                      strict_slash=True),
          RedirectRoute('/api/album/update/', 
                      handler='api.album.UpdateHandler', 
                      name = 'album-update',
                      strict_slash=True),
          RedirectRoute('/api/album/delete/', 
                      handler='api.album.DeleteHandler', 
                      name = 'album-delete',
                      strict_slash=True), 
          RedirectRoute('/api/album/<album_id:\d+>/photos/', 
                      handler='api.album.AlbumPhotosHandler', 
                      name = 'album-photos',
                      strict_slash=True),           
          RedirectRoute('/api/album/event/<event_id:\d+>/cover-photos/', 
                      handler='api.album.CoverAlbumHandler', 
                      name = 'album-cover-photos',
                      strict_slash=True),           
          RedirectRoute('/api/album/event/<event_id:\d+>/default-photos/', 
                      handler='api.album.DefaultAlbumHandler', 
                      name = 'album-default-photos',
                      strict_slash=True),           
          RedirectRoute('/api/album/user/<user_id:\d+>/', 
                      handler='api.album.UserAlbumHandler', 
                      name = 'album-of-user',
                      strict_slash=True),  
          RedirectRoute('/api/album/event/<event_id:\d+>/', 
                      handler='api.album.EventAlbumHandler', 
                      name = 'album-of-event',
                      strict_slash=True),  
          
           # Photo
          RedirectRoute('/api/photo/create/', 
                      handler='api.photo.CreateHandler', 
                      name = 'photo-create',
                      strict_slash=True),
          RedirectRoute('/api/photo/read/<photo_id:\d+>/',
                      handler='api.photo.ReadHandler', 
                      name = 'photo-read',
                      strict_slash=True),
          RedirectRoute('/api/photo/update/', 
                      handler='api.photo.UpdateHandler', 
                      name = 'photo-update',
                      strict_slash=True),
          RedirectRoute('/api/photo/delete/', 
                      handler='api.photo.DeleteHandler', 
                      name = 'photo-delete',
                      strict_slash=True),   
          RedirectRoute('/api/photo/delete-list/', 
                      handler='api.photo.DeleteListHandler', 
                      name = 'photo-delete-list',
                      strict_slash=True),     
          RedirectRoute('/api/photo/get-upload-url/', 
                      handler='api.photo.GetUploadURLHandler', 
                      name = 'get-upload-url',
                      strict_slash=True),
          RedirectRoute('/api/photo/all/', 
                      handler='api.photo.AllPhotosHandler', 
                      name = 'all-photos',
                      strict_slash=True),
                  
          # Event
          RedirectRoute('/api/event/create/', 
                      handler='api.event.CreateHandler', 
                      name = 'event-create',
                      strict_slash=True),
          RedirectRoute('/api/event/read/', 
                      handler='api.event.ReadHandler', 
                      name = 'event-read',
                      strict_slash=True),
          RedirectRoute('/api/event/update/', 
                      handler='api.event.UpdateHandler', 
                      name = 'event-update',
                      strict_slash=True),
          RedirectRoute('/api/event/delete/', 
                      handler='api.event.DeleteHandler', 
                      name = 'event-delete',
                      strict_slash=True),
          RedirectRoute('/api/event/getList/', 
                      handler='api.event.ReadListHandler', 
                      name = 'event-read-list',
                      strict_slash=True),
          
          
          # Event list 
          RedirectRoute('/api/user_event_list/create/', 
                      handler='api.user_event_list.CreateListHandler', 
                      name = 'event-list-create',
                      strict_slash=True),
          


          # Ticket
          RedirectRoute('/api/ticket/create/', 
                      handler='api.ticket.CreateHandler', 
                      name = 'ticket-create',
                      strict_slash=True),
          RedirectRoute('/api/ticket/read/', 
                      handler='api.ticket.ReadHandler', 
                      name = 'ticket-read',
                      strict_slash=True),
          RedirectRoute('/api/ticket/update/', 
                      handler='api.ticket.UpdateHandler', 
                      name = 'ticket-update',
                      strict_slash=True),
          RedirectRoute('/api/ticket/delete/', 
                      handler='api.ticket.DeleteHandler', 
                      name = 'ticket-delete',
                      strict_slash=True),

          # Poll
          RedirectRoute('/api/poll/create/', 
                      handler='api.poll.CreateHandler', 
                      name = 'poll-create',
                      strict_slash=True),
          RedirectRoute('/api/poll/read/', 
                      handler='api.poll.ReadHandler', 
                      name = 'poll-read',
                      strict_slash=True),
          RedirectRoute('/api/poll/update/', 
                      handler='api.poll.UpdateHandler', 
                      name = 'poll-update',
                      strict_slash=True),
          RedirectRoute('/api/poll/delete/', 
                      handler='api.poll.DeleteHandler', 
                      name = 'poll-delete',
                      strict_slash=True),
          RedirectRoute('/api/poll/all/<event_id:\d+>/', 
                      handler='api.poll.AllPollsHandler', 
                      name = 'poll-all',
                      strict_slash=True),

           # Answer
          RedirectRoute('/api/option/create/', 
                      handler='api.option.CreateHandler', 
                      name = 'option-create',
                      strict_slash=True),
          RedirectRoute('/api/option/read/', 
                      handler='api.option.ReadHandler', 
                      name = 'option-read',
                      strict_slash=True),
          RedirectRoute('/api/option/update/', 
                      handler='api.option.UpdateHandler', 
                      name = 'option-update',
                      strict_slash=True),
          RedirectRoute('/api/option/delete/', 
                      handler='api.option.DeleteHandler', 
                      name = 'option-delete',
                      strict_slash=True),

 
           # Response
          RedirectRoute('/api/response/create/', 
                      handler='api.response.CreateHandler', 
                      name = 'response-create',
                      strict_slash=True),
          RedirectRoute('/api/response/read/', 
                      handler='api.response.ReadHandler', 
                      name = 'response-read',
                      strict_slash=True),
          RedirectRoute('/api/response/update/', 
                      handler='api.response.UpdateHandler', 
                      name = 'response-update',
                      strict_slash=True),
          RedirectRoute('/api/response/delete/', 
                      handler='api.response.DeleteHandler', 
                      name = 'response-delete',
                      strict_slash=True),

           # Cron
          RedirectRoute('/cron/event-popularity/', 
                      handler='web.cron.EventPopularityHandler', 
                      name = 'cron-event-popularity',
                      strict_slash=True),
         
          # Chat
          RedirectRoute('/chat/', 
                      handler='web.chat_page.ChatHandler', 
                      name = 'chat',
                      strict_slash=True),
          
          # Auth
          RedirectRoute('/auth/login/', 
                      handler='web.authenticate.LoginHandler', 
                      name = 'login',
                      strict_slash=True),
          RedirectRoute('/auth/openid/<provider>/', 
                      handler='web.authenticate.OpenIDHandler', 
                      name = 'openid'),
          RedirectRoute('/auth/openid-result/<provider>/', 
                      handler='web.authenticate.OpenIDResultHandler', 
                      name = 'openid-result'),
          RedirectRoute('/auth/logout/', 
                      handler='web.authenticate.LogoutHandler', 
                      name = 'logout',
                      strict_slash=True),
          RedirectRoute('/auth/register/', 
                      handler='web.authenticate.RegisterHandler', 
                      name = 'register',
                      strict_slash=True),
          RedirectRoute('/auth/facebook-login/', 
                      handler='web.authenticate.FacebookHandler', 
                      name = 'facebook-login',
                      strict_slash=True),
          RedirectRoute('/auth/confirm-email/', 
                      handler='web.authenticate.ConfirmEmailHandler', 
                      name = 'confirm-email',
                      strict_slash=True),
          RedirectRoute('/auth/reset-password/', 
                      handler='web.authenticate.ResetPasswordHandler', 
                      name = 'reset-password',
                      strict_slash=True),
          RedirectRoute('/auth/reset-password-complete/', 
                      handler='web.authenticate.ResetPasswordCompleteHandler', 
                      name = 'reset-password-complete',
                      strict_slash=True)]

config = {
          'webapp2_extras.sessions': {
                                      'secret_key': 'foo'
                                      } 
          }

#ndb.toplevel to make sure all async requests finish before handler exits
app = ndb.toplevel(webapp2.WSGIApplication(routes, config=config))